package com.hks.quart.task;

import com.hks.quart.entity.ScheduleJobBean;
import com.hks.quart.utils.OkHttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component("commonTask")
public class CommonTask implements TaskService {

    private static final Logger LOG = LoggerFactory.getLogger(CommonTask.class.getName()) ;

    private static final SimpleDateFormat format =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;

    @Override
    public String run(ScheduleJobBean jobBean) {
        String result;
        try {
             result = OkHttpUtils.getInstance().postJsonParams(jobBean.getApplicationUrl(), jobBean.getParams());
            LOG.info("result === >> " + result);
            LOG.info("当前时间::::" + format.format(new Date()));
            return result;
        } catch (Exception e) {
            result = e.getMessage();
            e.printStackTrace();
            return result;
        }

    }
}
